home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / ibmsyn.zip / SEMFISRB.H < prev    next >
Text File  |  1992-06-16  |  11KB  |  181 lines

  1.  
  2. /* semfddrb.h */
  3.  
  4. /*****************************************************************************/
  5. /* NT IBM SDLC Adapter Device Driver: Receive buffer definitions */
  6. /*****************************************************************************/
  7.  
  8. /*****************************************************************************/
  9. /*                                                                           */
  10. /* Receive buffer definitions                                                */
  11. /*                                                                           */
  12. /* For receive, the object of the design is to miss as few frames as possible*/
  13. /* due to interrupt latency.                                                 */
  14. /*                                                                           */
  15. /* For PIO, this simply means that we service receiver at interrupt level    */
  16. /* (rather than DPC level) and, because we are controlling the chip, if we   */
  17. /* do overrun, we know about it immediately.                                 */
  18. /*                                                                           */
  19. /* For DMA, we have the vagary of the 8273 continuing to receive until       */
  20. /* disabled.  Note that DMA only usable for SDLC: for HDLC, we have to be    */
  21. /* full-duplex and, with only one DMA channel available, must use PIO.  The  */
  22. /* design uses the 'carry on receiving' feature of the 8273 by               */
  23. /*                                                                           */
  24. /* - creating 2 buffers that will receive at least 9 SDLC frames (9*269)     */
  25. /* - whenever we restart receiver, try to switch to t'other buffer if at all */
  26. /*   possible (i.e. if t'other buffer not in use)                            */
  27. /* - program the 8273 with a receive buffer size of the whole buffer at the  */
  28. /*   start of aforementioned receive sequence, and let it rip!               */
  29. /* - we only need to disable the receiver if it receives more than 8 full    */
  30. /*   frames worth (which it shouldn't in SDLC).                              */
  31. /*                                                                           */
  32. /* Late note: As of NT265, MmAllocateContiguous memory wasn't working for    */
  33. /* > 4K.  So reduce the rcvdatabuf_size so the whole RCVBUFFARRAY is < 4K.   */
  34. /*****************************************************************************/
  35.  
  36. #define RCVDATABUF_SIZE ((DEFAULT_FRAME_SIZE*7)+20)
  37.                                         /* 7 SDLC frames + final poll        */
  38.  
  39. typedef struct          _RCVBUF
  40. {
  41.    TRC_NAME             Name;           /* name for tracing-2 bytes. To make */
  42.                                         /* macros work, always allocate      */
  43.    struct _RCVBUF     * OtherBuffer;
  44.    int                  FramesPut;      /* count of entries made in this buf */
  45.                                         /* (includes error frames if they    */
  46.                                         /* have to go into the buffer)       */
  47.    int                  FramesGot;      /* how many frames pulled by Get     */
  48.    PHYSICAL_ADDRESS     DataPhysAddr;   /* &Data as physical address         */
  49.    UCHAR                Data [RCVDATABUF_SIZE];
  50. }                       RCVBUF,
  51.                      * PRCVBUF,
  52.                         RCVBUFARRAY[2];
  53.  
  54. #define RCVBUF_INUSE(bufptr) (bufptr->FramesPut NE bufptr->FramesGot)
  55.  
  56. #define RCVBUF_INIT(pDX, index)                                                \
  57.       {                                                                        \
  58.         PRCVBUF pRcvBuf         = & pDX->RcvInfo.pRcvBufArray[index];          \
  59.         pRcvBuf->Name[0]        = 'R';                                         \
  60.         pRcvBuf->Name[1]        = CAST ('0'+(index),UCHAR);                    \
  61.         ASSERT ((index & 0xFFFE) EQ 0); /* only 0 or 1 allowed               */\
  62.         pRcvBuf->OtherBuffer    = &pDX->RcvInfo.pRcvBufArray[1-(index)];       \
  63.         pRcvBuf->FramesPut      = 0;                                           \
  64.         pRcvBuf->FramesGot      = 0;                                           \
  65.         pRcvBuf->DataPhysAddr.LowPart = (ULONG)                                \
  66.            & ((CAST(pDX->RcvInfo.RcvBufPhysAddr.LowPart,PRCVBUF))[index].Data[0]);\
  67.         pRcvBuf->DataPhysAddr.HighPart= 0L;                                    \
  68.         ASSERT ((pRcvBuf->DataPhysAddr.LowPart & ~0xFFFFFF) EQ 0L);            \
  69.                                         /* should be within first 24 bits!   */\
  70.         TRACE_OBJECT(In,pDX->RcvInfo.pRcvBufArray[index]);                     \
  71.       }
  72.  
  73. /*****************************************************************************/
  74. /*                                                                           */
  75. /* The RFD (received frame descriptor is created a) at start of day, or b)   */
  76. /* after every receive completion.  The NowBeingPut RFD describes the RFD we */
  77. /* are receiving into (if receiver active) or will use when Receiver next    */
  78. /* activated.  It is incomplete: the BufPtr and StartAddr are correct; but   */
  79. /* the RcvdDataLength and SDLC* stuff will not be filled in until EORx.      */
  80. /*                                                                           */
  81. /* The RFD array uses the old SNAPS HMOD approach of having the interrupt    */
  82. /* side increment NowBeingPut when a frame is correctly received and the     */
  83. /* read routines increment NextToGet.                                        */
  84. /*                                                                           */
  85. /*****************************************************************************/
  86.  
  87. typedef struct          _RFD        /* received frame descriptor */
  88. {
  89. #ifdef IBMSYNC_TRACE
  90.   TRC_NAME              Name;
  91. #endif
  92.   RCVBUF              * BufPtr;         /* pointer to the RCVBUF */
  93.   UCHAR               * StartAddr;      /* &Data[StartIndex] */
  94.   short                 StartIndex;     /* index in Data[] of Address byte */
  95.   short                 RcvdDataLength; /* only valid if valid frame for RFD */
  96.                                         /* received. This length is for data */
  97.                                         /* only (as read from chip in bufferd*/
  98.                                         /* mode).  User buffer needs 2 extra */
  99.                                         /* bytes for A & C.                  */
  100.   UCHAR                 SDLCAddressByte;
  101.   UCHAR                 SDLCControlByte;
  102. }                       RFD;
  103.  
  104. #define RFDARRAY_SIZE 9
  105.  
  106. /*****************************************************************************/
  107. /* The RCVINFO stuff is not moved about as a structure: it is collected as a */
  108. /* structure for ease of reference as there is so much of it.                */
  109. /*****************************************************************************/
  110.  
  111. typedef struct          _RCVINFO
  112. {
  113.         PMDL            pRcvMdl;
  114.         PRCVBUF         pRcvBufArray;       /* actually a ptr to RCVBUF [2]  */
  115.         PHYSICAL_ADDRESS RcvBufPhysAddr;    /* -> start of whole RCVBUF array*/
  116.                                             /* not just 'Data' area          */
  117.         RFD             RFDArray [RFDARRAY_SIZE];
  118.  
  119.         short           RFDNowBeingPut;
  120.         short           RFDNextToGet;
  121. }                       RCVINFO;
  122.  
  123. #ifdef IBMSYNC_TRACE
  124. #define RFDARRAY_INIT_NAMES(pDX)                                               \
  125.                           {                                                    \
  126.                             short i;                                           \
  127.                             for (i=0; i<RFDARRAY_SIZE; i++)                    \
  128.                             {                                                  \
  129.                               pDX->RcvInfo.RFDArray[i].Name[0] = 'D';          \
  130.                               pDX->RcvInfo.RFDArray[i].Name[1] = CAST('0'+i,   \
  131.                                                                       UCHAR);  \
  132.                             }                                                  \
  133.                           }
  134. #else
  135. #define RFDARRAY_INIT_NAMES(pDX)
  136. #endif
  137.  
  138. #define RCVINFO_INIT(pDX)                                                      \
  139.                         { /* pRcvMdl,pRcvBufArray,PhysAddr set by AllocateDMA*/\
  140.                                                                                \
  141.                           RCVBUF_INIT(pDX, 0);                                 \
  142.                           RCVBUF_INIT(pDX, 1);                                 \
  143.                                                                                \
  144.                           pDX->RcvInfo.RFDArray[0].BufPtr =                    \
  145.                                                  &pDX->RcvInfo.pRcvBufArray[0];\
  146.                           pDX->RcvInfo.RFDArray[0].StartIndex = 0;             \
  147.                           pDX->RcvInfo.RFDArray[0].StartAddr =                 \
  148.                                        &(pDX->RcvInfo.pRcvBufArray[0].Data[0]);\
  149.                           pDX->RcvInfo.RFDArray[0].RcvdDataLength = -1;        \
  150.                                                                     /* debug */\
  151.                           RFDARRAY_INIT_NAMES(pDX);                            \
  152.                                                                                \
  153.                           pDX->RcvInfo.RFDNowBeingPut = 0;                     \
  154.                           pDX->RcvInfo.RFDNextToGet   = 0;                     \
  155.                                                                                \
  156.                           TRACE_EVENT(InRF);                                   \
  157.                         }
  158.  
  159. #define RFD_CAN_GET(pDX) (pDX->RcvInfo.RFDNextToGet NE pDX->RcvInfo.RFDNowBeingPut)
  160.  
  161. #define RFD_GOT(pDX) /* means: "We have pulled the data, move NextToGet on" */ \
  162. {                                                                              \
  163.    short *n = &pDX->RcvInfo.RFDNextToGet;                                      \
  164.                                                                                \
  165.    ASSERT(RFD_CAN_GET(pDX));                                                   \
  166.    ASSERT(pDX->RcvInfo.RFDArray[*n].RcvdDataLength NE -1);                     \
  167.                                                                                \
  168.    TRACE_OBJECT(Rg, pDX->RcvInfo.RFDArray[*n]);                                \
  169.                                                                                \
  170.    TRACE_DWORD (pDX->RcvInfo.RFDArray[*n].StartAddr);                          \
  171.                                                                                \
  172.    pDX->RcvInfo.RFDArray[*n].BufPtr->FramesGot++; /* may now be able to      */\
  173.                                                   /* refresh buffer          */\
  174.                                                                                \
  175.    *n = CAST((*n + 1) % RFDARRAY_SIZE, short);                                 \
  176.  }
  177.  
  178. #define RFD_PUT(pDX) /* means: "We have put another frames "                 */\
  179.    pDX->RcvInfo.RFDArray[pDX->RcvInfo.RFDNowBeingPut].BufPtr->FramesPut++;
  180.  
  181.